import pygal
from die import Die


# 创建2个D6骰子
die_1 = Die()
die_2 = Die()


# 投掷若干次骰子，并将结果（点数）存储在一个列表中
results = []

for i in range(1000):
    LV_result = die_1.roll() + die_2.roll()
    results.append(LV_result)

# print(results)


# 统计结果
frequencies = []
max_result = die_1.num_sides + die_2.num_sides

for value in range(2, max_result + 1):
    frequency = results.count(value)
    frequencies.append(frequency)

print(frequencies)


# 可视化结果
INS_hist = pygal.Bar()

INS_hist.title = "Results of rolling two D6 dice 1000 times."
INS_hist.x_labels = [x for x in range(2, max_result + 1)]
INS_hist.x_title = "Result"
INS_hist.y_title = "Frequency"

INS_hist.add("2 dice", frequencies)
INS_hist.render_to_file("15.4.7_dice_visual.svg")
